package com.example.synthesize.多线程.同步工具类countdownlatch;
import lombok.AllArgsConstructor;
import java.time.LocalTime;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * Created by IntelliJ IDEA2022.3.2
 * @Author: Tenghw
 * @Date: 2023/03/21  13:51
 * @Description:
 */
@AllArgsConstructor
public class Waiter implements Runnable{
    private CountDownLatch latch;
    private String name;

    @Override
    public void run() {
        try {
            System.out.println(LocalTime.now()+" : " +name+ " ,等待顾客都到齐...");
            latch.await();
            //latch.await(3, TimeUnit.SECONDS); //只会等待3秒
            System.out.println(LocalTime.now()+" : " +name+ " ,开始上菜！");
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

